import LoopObject from "@/loop";
import { CreepRole } from "@/role/types/role";
import RoleAttacker from "./roles/attacker";
import RoleCenterLabManager from "./roles/centerLabManager";
import RoleCenterManager from "./roles/centerManager";
import RoleClaimer from "./roles/claimer";
import RoleHarvester from "./roles/harvester";
import RoleManager from "./roles/manager";
import RoleProcessor from "./roles/processor";
import RoleRemoteHarvester from "./roles/remoteHarvester";
import RoleRemoteManager from "./roles/remoteManager";
import RoleRemoteWorker from "./roles/remoteWorker";
import RoleReserver from "./roles/reserver";
import RoleUpgrader from "./roles/upgrader";
import RoleWallFiller from "./roles/wallFiller";
import RoleWorker from "./roles/worker";

export default class CreepControlLoopObject extends LoopObject {

    tickStart(): void {
    }

    do(): void {

        const cpuUseds = {}

        Object.values(Game.creeps).forEach(creep => {

            if (!creep || creep.spawning) return

            if (creep.ticksToLive < 30 && creep.store[RESOURCE_GHODIUM_ACID] == 0 && creep.store[RESOURCE_ENERGY] == 0) {
                // creep.suicide()
                creep.say('我凉了')
                // if (creep.memory.room != CreepRole.Claimer)
                //     return
            }

            // const cpu = Game.cpu.getUsed()
            if (!cpuUseds[creep.memory.role]) cpuUseds[creep.memory.role] = 0

            switch (creep.memory.role) {
                case CreepRole.TaskManager:
                    //
                    creep.onWork()
                    break
                case CreepRole.CenterManager:
                    //
                    RoleCenterManager.loop(creep)
                    break
                case CreepRole.Processor:
                    //
                    RoleProcessor.loop(creep)
                    break
                case CreepRole.Harvester:
                    //
                    RoleHarvester.loop(creep)
                    break
                case CreepRole.Manager:
                    //
                    RoleManager.loop(creep)
                    break
                case CreepRole.Upgrader:
                    //
                    RoleUpgrader.loop(creep)
                    break
                case CreepRole.Worker:
                    //
                    RoleWorker.loop(creep)
                    break
                case CreepRole.RemoteManager:
                    //
                    RoleRemoteManager.loop(creep)
                    break
                case CreepRole.RemoteHarvester:
                    //
                    RoleRemoteHarvester.loop(creep)
                    break
                case CreepRole.WallerFiller:
                    //
                    RoleWallFiller.loop(creep)
                    break
                case CreepRole.Claimer:
                    //
                    RoleClaimer.loop(creep)
                    break
                case CreepRole.Reserver:
                    //
                    RoleReserver.loop(creep)
                    break
                case CreepRole.Attacker:
                    //
                    RoleAttacker.loop(creep)
                    break
                case CreepRole.RemoteWorker:
                    //
                    RoleRemoteWorker.loop(creep)
                    break
                case CreepRole.CenterLabManager:
                    //
                    RoleCenterLabManager.loop(creep)
                    break
                // case CreepRole.Miner:
                //     //
                //     break
            }

            // cpuUseds[creep.memory.role] += Game.cpu.getUsed() - cpu
        })

        // for(const name in cpuUseds) {
        //     if (cpuUseds[name] > 1.5) {
        //         console.log(name, cpuUseds[name])
        //     }
        // }


    }
    afterWork(): void {
    }
    tickEnd(): void {
    }
}
